package com.eightworld3.supermarket.controller;

import com.eightworld3.supermarket.domain.WareType;
import com.eightworld3.supermarket.service.WareTypeService;
import com.eightworld3.supermarket.service.dto.WareTypeDTO;
import com.eightworld3.supermarket.service.dto.add.WareTypeAddDTO;
import com.eightworld3.supermarket.service.dto.result.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author EightWorld3
 */
@Tag(name = "WareTypeController",description = "商品类型管理")
@RestController
@RequestMapping("/wareType")
public class WareTypeController {
    private final WareTypeService wareTypeService;

    /**
     * WareTypeController构造方法
     * @param wareTypeService 商品类型Service
     */
    public WareTypeController(WareTypeService wareTypeService){
        this.wareTypeService = wareTypeService;
    }

    //

    /**
     * 查询所有
     * @return 返回所有WareType(商品类型)
     */
    @Operation(summary = "查询所有商品类型(WareType)",description = "查询所有商品类型(WareType)")
    @GetMapping("/allWareType")
    public List<WareType> getAll(){
        return wareTypeService.selectAll();
    }

    /**
     * 根据wareTypeId查询WareType
     * @param wareTypeId ID号
     * @return 返回wareTypeId对应的WareType对象(经ResponseResult包装类修饰)
     */
    @Operation(summary = "根据wareTypeId查询商品类型(WareType)",description = "根据wareTypeId查询商品类型(WareType)")
    @GetMapping("/getWareTypeByWareTypeId/{wareTypeId}")
    public ResponseResult getWareTypeByWareTypeId(@PathVariable("wareTypeId")int wareTypeId){
        return wareTypeService.selectByWareTypeId(wareTypeId);
    }


    /**
     * 新增WareType
     * @param wareTypeAddDTO WareType新增DTO对象
     * @return 返回当前当次新增状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "新增商品类型(WareType)",description = "Test：类型名称(varchar(32)、备注(varchar(120))")
    @PostMapping("/addWareType")
    public ResponseResult addWareType(@RequestBody WareTypeAddDTO wareTypeAddDTO){
        return  wareTypeService.addWareType(wareTypeAddDTO);
    }

    /**
     * 更新WareType
     * @param wareTypeDTO WareType DTO对象
     * @return 返回当前当次更新状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "更新商品类型(WareType)",description = "Test：类型名称(varchar(32)、备注(varchar(120))")
    @PutMapping("/updateWareType")
    public ResponseResult updateWareType(@RequestBody WareTypeDTO wareTypeDTO){
        return wareTypeService.updateWareType(wareTypeDTO);
    }

    /**
     * 根据wareTypeId删除WareType
     * @param wareTypeId ID号
     * @return 返回当前当次删除状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "根据wareTypeId删除商品类型(WareType)",description = "根据wareTypeId删除商品类型(WareType)")
    @DeleteMapping("/deleteWareTypeByWareTypeId/{wareTypeId}")
    public ResponseResult deleteWareTypeByWareTypeId(@PathVariable("wareTypeId")int wareTypeId){
        return wareTypeService.deleteWareTypeByWareTypeId(wareTypeId);
    }
}
